package com.study.d012Components;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * Hpyerlink的使用
 * @author Administrator
 *
 */
public class HyperlinkMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		HBox hBox = new HBox();
		Hyperlink link =new Hyperlink("www.baidu.com", new Button("百度一下"));
		hBox.getChildren().add(link);
		stage.setScene(new Scene(hBox, 400, 300));
		stage.show();

		link.setVisited(true);

		// Hyperlink 默认不能跳转，需要自己设置点击事件
		link.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				HostServices services = getHostServices();
				services.showDocument(link.getText());

			}
		});

	}
}
